/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.ex;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;

/**
 * <p>Project: javase - AnnotationTest
 * <p>Powered by webrx On 2021-12-07 18:27:25
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
@Ann(name = "李四", value = 18, sex = "男")
public class AnnotationTest {
    @Ann(name = "李强", value = 88)
    public static void main(String[] args) throws NoSuchMethodException {
        var me = AnnotationTest.class;
        var m = me.getMethod("main", String[].class).getAnnotation(Ann.class);
        System.out.println(m);
        System.out.println(m.sex());
        System.out.println(m.name());
        System.out.println(m.value());
        if (me.isAnnotationPresent(Ann.class)) {
            var an = (Ann) me.getAnnotation(Ann.class);
            System.out.println(an.sex());
            System.out.println(an.value());
            System.out.println(an.name());
        }
    }
}

@Retention(RUNTIME)
@Target({TYPE, METHOD})
@interface Ann {
    String name();

    int value();

    String sex() default "女";
}
